<template>
  <div class="form-container">
    <el-form inline :model="form" ref="refForm" class="form-line" label-width="70">
      <el-form-item label="反馈来源" prop="feedbackOrigin">
        <el-select @change="handleSearch" v-model="form.feedbackOrigin" placeholder="请选择反馈来源">
          <el-option label="攸诺城配" value="1"></el-option>
          <el-option label="攸诺运管" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select @change="handleSearch" size="default" v-model="form.status" placeholder="请选择状态">
          <el-option label="未回复" value="1"></el-option>
          <el-option label="已回复" value="2"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div class="btn-container">
      <el-button type="primary" @click="handleReset(refForm as FormInstance)">重置</el-button>
      <el-button type="primary" @click="handleSearch">查询</el-button>
    </div>
  </div>
  <div class="table-container">
    <el-table
      border
      :cell-style="{ textAlign: 'center', fontSize: '13px' }"
      :header-cell-style="{
        textAlign: 'center',
        fontWeight: '100',
        fontSize: '13px',
        color: 'white',
        backgroundColor: '#009688'
      }"
      style="width: 100%"
      :data="tableData"
    >
      <el-table-column fixed prop="feedbackOrigin" label="反馈来源">
        <template #default="scope">{{ scope.row.feedbackOrigin == "1" ? "攸诺城配" : "攸诺运管" }}</template>
      </el-table-column>
      <el-table-column prop="feedbackTypeName" label="反馈类型">
        <template #default="scope">{{ scope.row.feedbackTypeParentName }}/{{ scope.row.feedbackTypeName }}</template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template #default="scope">{{ scope.row.status == "1" ? "未回复" : "已回复" }}</template>
      </el-table-column>
      <el-table-column prop="createTime" label="反馈时间" />
      <el-table-column fixed="right" label="操作">
        <template #default="scope">
          <!-- <el-button link type="primary" size="small" @click="handleDelete(scope.row.id)">删除</el-button> -->
          <!-- <el-button link type="primary" size="small" @click="handleEdit(scope.row.id)"> 修改 </el-button> -->
          <el-button link type="primary" size="small" @click="handleDetail(scope.row.id)"> 详情 </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  <div class="pagination-container">
    <el-pagination
      background
      size="small"
      layout="prev, pager, next"
      :total="pageTotal"
      v-model:current-page="form.pageNum"
      :page-size="form.pageSize"
    />
  </div>
  <!-- <div class="pagination-container">
    <el-pagination
      background
      size="small"
      layout="prev, pager, next"
      :total="pageTotal"
      :page-size="form.pageSize"
      :current-page="form.pageNum"
      @change="getFeedbackList"
    />
  </div> -->
</template>

<script setup lang="tsx" name="useProTable">
import { Base } from "@/api/interface/province/base";
import { getFeedbackListAPI } from "@/api/modules/province/baseAPI";
import { ElMessage, FormInstance } from "element-plus";
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
let pageTotal = ref<number>(0);
const router = useRouter();
const form = ref<{
  feedbackOrigin: string;
  status: string;
  pageNum: number;
  pageSize: number;
}>({
  feedbackOrigin: "",
  status: "",
  pageNum: 1,
  pageSize: 10
});
const refForm = ref<FormInstance>();
const tableData = ref<Base.Row[]>([]);
const handleReset = (formEl: FormInstance) => {
  formEl.resetFields();
  form.value.pageNum = 1;
  getFeedbackList();
};
const handleSearch = () => {
  form.value.pageNum = 1;
  getFeedbackList();
};
const handleDetail = (id: string) => {
  router.push({ path: "/provinceLevel/proBasic/proOpinion/detail", query: { id: id } });
};
const getFeedbackList = async () => {
  const { code, rows, total, msg } = await getFeedbackListAPI(form.value);
  if (code == "200") {
    if (rows) {
      tableData.value = rows;
    } else {
      tableData.value = [];
    }
    if (total) {
      pageTotal.value = total;
    }
  } else {
    ElMessage.error(msg);
  }
};
onMounted(() => {
  getFeedbackList();
});
</script>
<style lang="scss" scoped>
.form-container {
  padding: 10px;
  margin-bottom: 10px;
  background-color: white;
  .btn-container {
    display: inline-block;
    float: right;
    vertical-align: middle;
    ::v-deep .el-button > span {
      font-size: 13px;
    }
  }
  .el-form {
    display: inline-block;
    ::v-deep .el-form-item__label {
      font-size: 13px;
    }
  }
  .form-line {
    .el-form-item {
      width: 280px;
      margin: 0;

      // margin-right: 20px;
    }
    .el-input {
      width: 240px;
    }
    .el-select {
      width: 240px;
    }
  }
}
.table-container {
  padding: 40px 10px;
  padding-bottom: 60px;
  background-color: white;
}
.pagination-container {
  // display: inline-block;
  float: right;
  margin-top: -40px;
  margin-right: 10px;
  background-color: white;
  border: 1px solis red;
}
</style>
